<?php

namespace app\common\model;

use think\Model;


class GoodsCategory extends Model
{

    // 表名
    protected $name = 'goods_category';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];

    public function getImageAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['image']) ? $data['image'] : '');
        return get_app_image_url($value);
    }

    public function getPcImageAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pc_image']) ? $data['pc_image'] : '');
        return get_app_image_url($value);
    }

    /**
     * 读取分类列表
     * @param string $type   指定类型
     * @param string $status 指定状态
     * @return array
     */
    public static function getCategoryArray($type = null, $status = null)
    {
        $list = collection(self::where(function ($query) use ($type, $status) {
            if (!is_null($type)) {
                $query->where('type', '=', $type);
            }
            if (!is_null($status)) {
                $query->where('status', '=', $status);
            }
        })->order('weigh', 'desc')->select())->toArray();
        return $list;
    }
    /**
     * 分类名获取
     * */
    public static function getInfo($id,$feild='*'){
        $where['id'] = $id;
        return self::where($where)
            ->field($feild)
            ->find();
    }

}
